package com.luoxiang.socialandroid.adapter

import android.view.View
import android.widget.ImageView
import com.baidu.mapapi.search.sug.SuggestionResult.SuggestionInfo
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.luoxiang.socialandroid.R

class PositionAdapter(data: MutableList<SuggestionInfo>) : BaseQuickAdapter<SuggestionInfo,BaseViewHolder>(R.layout.item_address,data) {
    var indexPosition: Int? = null

    override fun convert(holder: BaseViewHolder, item: SuggestionInfo) {
        holder.apply {
            setText(R.id.textTitle,item.key)
            setText(R.id.textContent,item.address)
            if(indexPosition != null && indexPosition == layoutPosition){
                getView<ImageView>(R.id.imageCheck).visibility = View.VISIBLE
            }else{
                getView<ImageView>(R.id.imageCheck).visibility = View.INVISIBLE
            }
            if(layoutPosition == 0||!(data[layoutPosition].city.equals(data[layoutPosition-1].city))){
                setGone(R.id.textCity,false)
                setGone(R.id.view4,false)
                setText(R.id.textCity, item.city)
            }else{
                setGone(R.id.textCity,true)
                setGone(R.id.view4,true)
            }
        }
    }
}